package com.ia.aistream.controller.operating;

import java.util.List;

import com.ia.aistream.common.annotation.Log;
import com.ia.aistream.model.operating.entity.DocIndex;
import com.ia.aistream.service.operating.IDocIndexService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ia.aistream.common.enums.BusinessType;

import com.ia.aistream.common.core.controller.BaseController;
import com.ia.aistream.common.core.domain.AjaxResult;
import com.ia.aistream.common.utils.poi.ExcelUtil;
import com.ia.aistream.common.core.page.TableDataInfo;

/**
 * 文件索引信息表Controller
 * 
 * @author aistream
 * @date 2021-01-25
 */
@Controller
@RequestMapping("/aistream/index")
public class DocIndexController extends BaseController
{
    private String prefix = "aistream/index";

    @Autowired
    private IDocIndexService docIndexService;

    @RequiresPermissions("aistream:index:view")
    @GetMapping()
    public String index()
    {
        return prefix + "/index";
    }

    /**
     * 查询文件索引信息表列表
     */
    @RequiresPermissions("aistream:index:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DocIndex docIndex)
    {
        startPage();
        List<DocIndex> list = docIndexService.selectDocIndexList(docIndex);
        return getDataTable(list);
    }

    /**
     * 导出文件索引信息表列表
     */
    @RequiresPermissions("aistream:index:export")
    @Log(title = "文件索引信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DocIndex docIndex)
    {
        List<DocIndex> list = docIndexService.selectDocIndexList(docIndex);
        ExcelUtil<DocIndex> util = new ExcelUtil<DocIndex>(DocIndex.class);
        return util.exportExcel(list, "index");
    }

    /**
     * 新增文件索引信息表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件索引信息表
     */
    @RequiresPermissions("aistream:index:add")
    @Log(title = "文件索引信息表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DocIndex docIndex)
    {
        return toAjax(docIndexService.insertDocIndex(docIndex));
    }

    /**
     * 修改文件索引信息表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DocIndex docIndex = docIndexService.selectDocIndexById(id);
        mmap.put("docIndex", docIndex);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件索引信息表
     */
    @RequiresPermissions("aistream:index:edit")
    @Log(title = "文件索引信息表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DocIndex docIndex)
    {
        return toAjax(docIndexService.updateDocIndex(docIndex));
    }

    /**
     * 删除文件索引信息表
     */
    @RequiresPermissions("aistream:index:remove")
    @Log(title = "文件索引信息表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(docIndexService.deleteDocIndexByIds(ids));
    }
}
